1 using UnityEngine;
2 using
System.Collections;
3
4 namespace
GamePlay
5 {
6     
public class Bullet : MonoBehaviour
7     {
8         
private Vector3 speed;
9         
private bool isRunning;
10         
private float stateTime;
11
12         
public int animalIndex { get; set; }
13         
public SkillType skillType;// { get; set; }
14
15         
private bool isParabol;
16         
17         
void Start()
18         {
19             speed =
new Vector3(10f, 0, 0);
20             stateTime =
3;
21             isRunning =
true;
22         }
23
24         
void Update()
25         {
26             
if (isRunning)
27             {
28                 
switch (skillType)
29                 {
30                     
case SkillType.LUA:
31                     
case SkillType.DONGBANG:
32                     
case SkillType.SET:
33                     
case SkillType.DOICHO:
34                         line();
35                         
break;
36                     
case SkillType.THIENTHACH:
37                         parabol();
38                         
break;
39                 }
40
41             }
42         }
43
44         
private void line()
45         {
46             
//transform.Translate(speed * Time.deltaTime);
47             
//transform.localPosition += speed * Time.deltaTime;
48             GetComponent<Rigidbody2D>().velocity = speed;
49             stateTime -= Time.deltaTime;
50             
if (stateTime <= 0)
51                 Destroy(gameObject);
52         }
53
54         
private void parabol()
55         {
56             
if (!isParabol)
57             {
58                 isParabol =
true;
59                 Rigidbody2D body = gameObject.AddComponent<Rigidbody2D>();
60                 body.velocity =
new Vector2(Random.Range(8f, 10f), 4);
61             }
62         }
63
64         
public void setRunning(bool isRunning)
65         {
66             
this.isRunning = isRunning;
67             
//collider2D.enabled = isRunning;
68             GetComponent<Rigidbody2D>().simulated = isRunning;
69         }
70
71         
public void OnTriggerEnter2D(Collider2D otherCollider)
72         {
73             
if (otherCollider.gameObject.name == MapObjectNames.DeadLine)
74             {
75                 Destroy(gameObject);
76             }
77             
else if (otherCollider.gameObject.name == MapObjectNames.FinishObject)
78             {
79                 Destroy(gameObject);
80             }
81         }
82
83
84     }
85 }


public SkillType skillType; { get; set; }

transform.Translate(speed * Time.deltaTime);

transform.localPosition += speed * Time.deltaTime;

collider2D.enabled = isRunning;




Trò chơi đua xe động vật trong UNITY Engine 114.726 lượt xem

Gõ tìm kiếm nhanh...